const moment = require('moment');

module.exports = {

  listToTree: function(list) {
    const rJson = [];

    // 将所有的pid的数据加到对应的id数据对象里面去，需要添加一个属性children
    for (let i = 0; i < list.length; i++) {
      const arr = [];
      for (let j = 0; j < list.length; j++) {
        if (list[i].id === list[j].pid) {
          list[i].children = arr;
          arr.push(list[j]);
        }
      }
    }
    for (let i = 0; i < list.length; i++) {
      if (list[i].pid === 0) {
        rJson.push(list[i]);
      }
    }
    return rJson;
  },
  getDate: function(second){
    let data=moment.unix(second).format('YYYY-MM-DD');
    return data;
  },
  getDateTime: function(second){
    let data=moment.unix(second).format('YYYY-MM-DD HH:mm:ss');
    return data;
  },
  getSecond: function(){
    let data=Math.floor(new Date().getTime()/1000);
    return data;
  },
}; 
